package com.qianfeng.test.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.qianfeng.test.R;
import com.qianfeng.test.bean.menu_bean.ListEntity;
import com.qianfeng.test.constants.UrlConstans;
import com.qianfeng.test.task.ItemImageTask;
import com.qianfeng.test.utils.ImageLoaderHelper;

import java.util.List;

/**
 * Created by Administrator on 15-7-24.
 */
public class MenuAdapter extends AppBaseAdapter<ListEntity> {
    private DisplayImageOptions options;
    public MenuAdapter(List<ListEntity> list, Context context) {
        super(list, context);
        options = ImageLoaderHelper.getInstance().getDisplayImageOptions(R.mipmap.ic_launcher,R.mipmap.ic_launcher);

    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        convertView = inflater.inflate(R.layout.menu_left_item_layout,parent,false);
        ViewHolder vh = new ViewHolder(convertView);
        vh.menu_item_text.setText(list.get(position).getName());
        vh.menu_item_image.setImageResource(R.mipmap.ic_launcher);
        vh.menu_item_image.setTag(list.get(position).getIcon_show());//不懂
        String menu_picUrl = list.get(position).getIcon_show();
//        ItemImageTask task = new ItemImageTask(vh.menu_item_image);
//        task.execute(menu_picUrl);
        ImageLoader.getInstance().displayImage(menu_picUrl,vh.menu_item_image,options);
        return convertView;
    }
    private static class ViewHolder{
        private ImageView menu_item_image;
        private TextView menu_item_text;
        public ViewHolder(View convertView) {
            menu_item_image = (ImageView) convertView.findViewById(R.id.menu_item_imageView);
            menu_item_text = (TextView) convertView.findViewById(R.id.menu_item_textView);

        }
    }

}
